#include <iostream>
#include "MsgInstanceClient.h"
#include "Communication.h"
#include "string.h"
#include "time.h"
#include <signal.h>
#include "EventLoop.h"
#include "HistoryRecord.h"
#include "Hotplug.h"
#include "ComLog.h"
#include "SerialCommunication.h"
#include "MsgInstanceServer.h"
#include <pthread.h>
#include "ComTimer.h"

void *MsgClientTask1(void *arg)
{

     CMsgInstanceClient *msgClient = new CMsgInstanceClient(MSG_SERVER_ADDR, MSG_SERVER_PORT, KEEPALIVESENCOND);
     msgClient->MsgEventRegister(1, TEST_EVENT_1, msgClient, &CMsgInstanceClient::TestEventCB, NULL);
     msgClient->MsgEventRegister(1, TEST_EVENT_2, msgClient, &CMsgInstanceClient::TestEventCB, NULL);
     msgClient->MsgEventRegister(1, TEST_EVENT_3, msgClient, &CMsgInstanceClient::TestEventCB, NULL);
     while(1)
     {
         msgClient->MsgSchedule();
         msgClient->MsgPublish(TEST_EVENT_4, (char *)"dadasd1", 7, 0);
         msgClient->MsgPublish(TEST_EVENT_5, (char *)"dadasd2", 7, 0);
         msgClient->MsgPublish(TEST_EVENT_6, (char *)"dadasd3", 7, 0);
         usleep(2000000);
     }

}


void *MsgClientTask(void *arg)
{

     CMsgInstanceClient *msgClient = new CMsgInstanceClient(MSG_SERVER_ADDR, MSG_SERVER_PORT, KEEPALIVESENCOND);
     msgClient->MsgEventRegister(2, TEST_EVENT_4, msgClient, &CMsgInstanceClient::TestEventCB, NULL);
     msgClient->MsgEventRegister(2, TEST_EVENT_5, msgClient, &CMsgInstanceClient::TestEventCB, NULL);
     msgClient->MsgEventRegister(2, TEST_EVENT_6, msgClient, &CMsgInstanceClient::TestEventCB, NULL);
     while(1)
     {
         msgClient->MsgSchedule();
         msgClient->MsgPublish(TEST_EVENT_1, (char *)"dadasd4", 7, 0);
         msgClient->MsgPublish(TEST_EVENT_2, (char *)"dadasd5", 7, 0);
         msgClient->MsgPublish(TEST_EVENT_3, (char *)"dadasd6", 7, 0);
         usleep(2000000);
     }

}


pthread_t msgclient ;
pthread_t msgclient1 ;

void timer1scb(void *data)
{
     COMLOG_ERROR_LOG("timer cb data:%s\n",data);
 
}
int main()
{
    ComLogSetLevel(COMLOG_FATAL);
    ComTimerAdd(timer1scb, 500, 1, (char *)"DSADASDASDSA");
    while(1)
    {
         ComTimerSchedule();
         usleep(30000);
    }
    #if  0
    signal(SIGPIPE, SIG_IGN);
   CMsgInstanceServer *msgs = new CMsgInstanceServer();
   pthread_create(&(msgclient), NULL, MsgClientTask, NULL);
   pthread_create(&(msgclient1), NULL, MsgClientTask1, NULL);
   while(1)
   {
      msgs->MsgServerSchedule();
      usleep(30000);
   }
   #endif
    return 0;
}